//
//  SettingsViewController.m
//  Wechat
//
//  Created by FONERY on 2019/9/9.
//  Copyright © 2019 Zhangfan. All rights reserved.
//

#import "SettingsViewController.h"
#import "SettingsModel.h"
#import "SettingsTableViewCell.h"

@interface SettingsViewController () <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *exitBtn;

@property (nonatomic, strong) NSArray *settingsArr;
@end

@implementation SettingsViewController

- (NSArray *)settingsArr {
    if (!_settingsArr) {
        SettingsModel *secure = [[SettingsModel alloc] init];
        secure.title = @"安全中心";
        
        SettingsModel *msgNotification = [[SettingsModel alloc] init];
        msgNotification.title = @"消息提醒";
        msgNotification.type = SettingsTableViewCellTypeSwitch;
        
        SettingsModel *msgAlert = [[SettingsModel alloc] init];
        msgAlert.title = @"通知提示音";
        msgAlert.type = SettingsTableViewCellTypeSwitch;
        
        SettingsModel *listenMode = [[SettingsModel alloc] init];
        listenMode.title = @"听筒模式";
        listenMode.type = SettingsTableViewCellTypeSwitch;
        
        SettingsModel *busy = [[SettingsModel alloc] init];
        busy.title = @"免打扰";
        busy.detail = @"已关闭";
        busy.type = SettingsTableViewCellTypeDetail;
        
        SettingsModel *clearMsgHistory = [[SettingsModel alloc] init];
        clearMsgHistory.title = @"清空所有聊天记录";
        
        SettingsModel *clearCache = [[SettingsModel alloc] init];
        clearCache.title = @"清理缓存";
        clearCache.detail = @"0.00 M";
        clearCache.type = SettingsTableViewCellTypeDetail;
        
        SettingsModel *about = [[SettingsModel alloc] init];
        about.title = @"关于";
        
        _settingsArr = @[@[secure], @[msgNotification], @[msgAlert, listenMode], @[busy], @[clearMsgHistory, clearCache], @[about]];
    }
    return _settingsArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"设置";
    self.exitBtn.layer.cornerRadius = 6;
    self.exitBtn.layer.masksToBounds = YES;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.settingsArr count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.settingsArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SettingsTableViewCell *cell = [SettingsTableViewCell cellWithTableView:tableView];
    cell.settingsModel = self.settingsArr[indexPath.section][indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [SettingsTableViewCell cellHeight];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 8;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}

@end
